<template>
  <div v-drag>
    <div class="mask" @click="closePopup(false)"></div>
    <div class="edit_box" v-loading="loading">
      <div class="box_head">
        <p>{{ type==1?'收货地址审核':'收货地址详情' }}</p>
        <i @click="closePopup(false)"></i>
      </div>
      <div class="box_body">
        <div class="line">
          <span class="lab">用户：</span>
          <div>{{owner}}{{remark ? `(${remark})` :''}}{{(!owner)&&(!remark) ? '——' :''}}</div>
        </div>
        <div class="line">
          <span class="lab">收货地址：</span>
          <div>{{address?address:'——'}} </div>
        </div>
        <div class="line">
          <span class="lab">详细地址：</span>
          <div style="line-height: 25px">{{addressInfo?addressInfo:'——'}} </div>
        </div>
        <div class="line">
          <span class="lab">门牌号：</span>
          <div>{{house?house:'——'}}</div>
        </div>
        <div class="line">
          <span class="lab">收货人：</span>
          <div>{{userName?userName:'——'}}</div>
        </div>
        <div class="line">
          <span class="lab">电话号码：</span>
          <div>{{phone?phone:'——'}} </div>
        </div>

        <div class="line">
          <span class="lab">是否需要爬楼：</span>
          <div :style="'color:'+(isExtra?'#67c430':'#e40000')">{{isExtra?'是':'否'}}</div>
        </div>

        <div class="line">
          <span class="lab">是否默认地址：</span>
          <div :style="'color:'+(isDefault?'#67c430':'#e40000')">{{isDefault?'是':'否'}}</div>
        </div>

        <div class="line">
          <span class="lab">状态：</span>
          <div :style="'color:'+(proStatus?'#67c430':'orange')">{{proStatus?'已审核':'待审核'}}</div>
        </div>
        <p class="error_line">{{infoTip}}</p>
      </div>
      <div class="box_foot">
        <span @click="closePopup(false)">取消</span>
        <span @click="closePopup(false)" v-if="parseFloat(type)===0">确定</span>
        <span @click="confirmEdit" v-else>通过</span>
      </div>
    </div>
  </div>
</template>

<script>
import { getDetail, checkAddress } from "@/api/data/user/address";

export default {
  props:['addressId','type','remark'],
  data(){
    return {
      owner:'',
      userName: '',
      userId:this.addressId ? this.addressId :'',
      userOption:[],
      warehouseOption:[],
      proStatus:1,
      phone:'',
      address:'',
      isExtra:0,
      isDefault:0,
      house:'',
      addressInfo:'',
      infoTip: '',
      tip_num: '',
      loading:false,
    }
  },
  mounted() {
    if (this.addressId){
      this.getDetail();
    }
  },
  methods:{
    getDetail(){
      let that = this;
      this.loading = true;
      getDetail(that.addressId).then(res => {
        if (res){
          that.setData(res);
        }
        that.loading = false;
      }).catch((e) => {
        that.loading = false;
      });
    },

    setData(obj){
      this.userName=obj.name?obj.name:'';
      this.userId = obj.userId?obj.userId:'';
      this.proStatus= obj.warehouseEnable?obj.warehouseEnable:0;
      this.house = obj.house ? obj.house :'';
      this.phone = obj.phone?obj.phone:'';
      this.address = obj.address?obj.address:'';
      this.isExtra = obj.isExtra?obj.isExtra:0;
      this.isDefault = obj.isDefault?obj.isDefault:0;
      this.addressInfo = obj.addressInfo ? obj.addressInfo : '';
      this.owner = obj.userName ? obj.userName : '';
    },

    // 确认编辑
    confirmEdit(){
      let that = this;
      that.$confirm('确定该地址无误?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        return checkAddress({id:this.addressId})
      }).then(() => {
        that.closePopup(true);
        that.$message.success({
          message:'操作成功！',
          duration:1500
        });
      }).catch(() => {
      });
    },

    // 关闭
    closePopup(refresh){
      this.$emit('listenToChild', {refresh: refresh})
    }
  }
}
</script>

<style scoped>

</style>
